Developer Documentation
PATH  Mac OS X Documentation > Developer Tools > The Objective-C Compiler


Previous | Contents | Next

String Constants and Static Strings

GNU CC normally makes string constants read-only, and if several identical string constants are used, GNU CC stores only one copy of the string.

Some C libraries incorrectly write into string constants. The best solution to this problem is to use character array variables with initialization strings instead of string constants. If this isn't possible, use the -fwritable-strings flag, which directs GNU CC to handle string constants the way most C compilers do.

Also note that initialized strings are normally put in the text segment by the GNU compiler, and attempts to write to them cause segmentation faults. If your program depends on being able to write initialized strings, there are two ways to get around this problem:

char *non_writable = "You can't write this string"; char writable[] = "You can write this string";


The Objective-C Compiler

Previous | Contents | Next